<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label>骨灰堂编号</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.AssnameLike" placeholder="请输入骨灰堂编号" @keydown.enter.native="btnSearch"></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label>取出日期从</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.AshtakdateGreaterAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/> 到
          <el-date-picker v-date v-model="selectData.AshtakdateLessAndEquals" type="date" placeholder="请选择日期" style="width:160px;" @change="btnSearch"/>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">逝者姓名</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.RegnameLike" placeholder="请输入逝者姓名" @keydown.enter.native="btnSearch"></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">寄存卡号</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.ASHNUMBER" placeholder="请输入寄存卡号" @keydown.enter.native="btnSearch"></el-input>
        </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading" style="margin-left:20px;">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    
    <!-- 功能列表 -->
    <div style="margin-top:10px;">
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li><el-button type="primary" @click="exportExcel">导出</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :hiddenPageOrder="false" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <!-- 操作弹窗 -->
    <main-model ref="dialog" @refreshData="getData"></main-model>
    <sweet-modal ref="Print" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <iframe :src="printUrl" style="width:1100px; height:500px;margin-top:20px;"></iframe>
    </sweet-modal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/common.scss";
  .el-button+.el-button {
    margin-left: 0;
  }
  .btnCenter {
    text-align: center;
  }
</style>
<script>
  import sweetModal from "@/components/sweetModal";
  import mainModel from './assUseMain';
  import dataTable from "@/components/Table/DataTable";
  import apiBase from "@/api/apiBase.js";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  const ADD = "新增";
  const MODIFY = "修改";
  const DELETE = "删除";
  const INFO = "详情";
  const END = "结束使用";
  const BEG = "开始使用";
  const CONTINUE = "使用续存";
  const REG = "登记";
  export default {
    name: "assUse",
    mixins: [manage],
    data() {
      return {
        pageWidth: 1200,
        selectData: {},
        statusTypes: {},
        printUrl: null,
        title: null,
      };
    },
    methods: {
      exportExcel() {
            var header
            var startTime
            if(this.selectData.AshtakdateGreaterAndEquals){
                startTime = this.selectData.AshtakdateGreaterAndEquals.toLocaleDateString();
            }else{
                startTime = '空';
            }
            
            if(this.selectData.AshtakdateLessAndEquals != null){
                var endTime = this.selectData.AshtakdateLessAndEquals.toLocaleDateString();
                header = '取走汇总表' + '(' + startTime + '--' + endTime + ')';
            }else{
                header = '取走汇总表' + '(' + startTime + '--' + '空' + ')';
            }
            if (this.dataList.length === 0){
                this.$message.error("无导出数据！");
                return;
            }
            this.downloadLoading = true;
            
            require.ensure([], () => {
                const { export_json_to_excel } = require("@/vendor/Export2Excel");
                export_json_to_excel(this.headList, this.dataList, header);
                this.downloadLoading = false;
            });
        },
       //功能操作
      operate(order) {
        this.order = order;
        switch (this.order) {
          case INFO:
            this.$refs.dialog.open(this.order,this.currentRow);
            break;
        }
      },
      //获取表头
      getCreColumn() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Column.GetAshesTakeReportColumns,
          res => {
            this.headList = res.data.content;
          });
      },
      //获取查询数据
      getData() {
        this.dataList = [];
        let Data = JSON.parse(JSON.stringify(this.selectData));
        if (Data.AshtakdateGreaterAndEquals)
          Data.AshtakdateGreaterAndEquals = formatDate(Data.AshtakdateGreaterAndEquals, "yyyyMMdd");
        if (Data.AshtakdateLessAndEquals)
          Data.AshtakdateLessAndEquals = formatDate(Data.AshtakdateLessAndEquals, "yyyyMMdd");
        let data = {
          PageIndex: -1,
          PageSize: 0,
          OrderBy: this.pageOrder.orderType,
          OrderByType: this.pageOrder.orderSort,
          Data: Data
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().AshesUse.Query,
          res => {
            let copydata = res.data.content.OutData;
            copydata.forEach(item => {
                if(item.ASHSTATUS === "B"){
                    this.dataList.push(item);
                }
            });
            // this.dataList = res.data.content.OutData;
            // this.pageOrder.totalNum = res.data.content.RecordCount;
            // this.pageOrder.totalNum = this.dataList.length;
            
          });
      },
      //重置查询
      btnRepeat() {
        this.selectData = {
          
        };
        this.getData();
      },
       // 控制是否显示
      btnShow(val){
       
      },
    },
    components: {
      mainModel,
      dataTable,
      sweetModal
    },
    created() {
      this.getCreColumn();
      this.getData();
    }
  };
</script>
